<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
jimport( 'joomla.application.component.view' );

class JAJobBoardViewJAEmployers extends JAView
{
    /**
     * Display the view
     */
    function display($tmpl = null)
    {
    	global $option;
    	
    	require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'asset'.DS.'rendfield.php');
		$task = JRequest::getVar("task", '');
		switch ($task){			
			case 'profile':				
				JAJobBoardViewJAEmployers::displayProfile();
				break;	
			case 'user':				
				JAJobBoardViewJAEmployers::displayForm();				
				break;
			case 'account':
				JAJobBoardViewJAEmployers::displayAccount();
				break;
			case 'invoices':
				JAJobBoardViewJAEmployers::displayInvoices();
				break;
			default:
				JAJobBoardViewJAEmployers::displayListItems();
		}
		
		parent::display($tmpl);
  	}
  	
  	function displayInvoices()
  	{
  		$filter_invoice_type = JRequest::getVar('filter_invoice_type');
  		$items = $this->get('Invoices');
  		$viewFieldList = $this->get('viewFieldList');
  		$pagination = $this->get(Pagination);
  		$arr_invoicetype = array();
  		
  		$arr_invoicetype[0]->value = '';
  		$arr_invoicetype[0]->text = '--------------'.JText::_('ALL').'--------------';
  		$arr_invoicetype[1]->value = 'c';
  		$arr_invoicetype[1]->text = JText::_('Credit Invoice');
  		$arr_invoicetype[2]->value = 's';
  		$arr_invoicetype[2]->text = JText::_('Subscription Invoice');
  		$arr_invoicetype[3]->value = 'p';
  		$arr_invoicetype[3]->text = JText::_('Posting Plan Invoice');
  		$invoice_typeObject = JHTML::_('select.genericlist',   $arr_invoicetype, 'filter_invoice_type', 'class="inputbox" size="1" onchange="adminForm.submit();"', 'value', 'text',$filter_invoice_type);
  		
  		$this->assignRef('invoice_typeObject',$invoice_typeObject);
  		$this->assignRef('pagination',$pagination);
  		$this->assignRef('fieldList',$viewFieldList);
  		$this->assignRef('items',$items);
  	}
  	
  	
  	function displayAccount()
  	{
  		$item = $this->get('CurrentAccInfo');
  		$this->assignRef('item', $item );
  	}
  	
  	
  	/**
  	* Display List of items
  	*/
  	function displayListItems(){  		
  		global $mainframe, $option;     
  		
  		$fieldList = &$this->get('EditFieldList');
  		   
        // get data items
       	$items = &$this->get('Items');  

		$pagination = &$this->get('Pagination');
        
        $lists = $this->_getViewLists($fieldList);
        
        $ordering = true;              
                
		// build the html select list
		

        $this->assignRef('items', $items);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('fieldlist', $fieldList);
        $this->assignRef('lists', $lists);
        $this->assignRef('ordering', $ordering );
  	}
  	
  	/**
  	* Display edit/add Profile
  	*/
  	function displayProfile(){  	    
  		global $option;
  		
  	    $item = &$this->get('ProfileItem');  	
		$fieldList = &$this->get('EditFieldList');
		
		$item = parse_content_item($item, $fieldList);		
		$this->setLayout('profile');
		$this->assignRef('fieldlist', $fieldList);
  	    $this->assignRef('option', $option);
  	    $this->assignRef('item', $item);

	}	
	
	/**
  	* Display edit/add Employer
  	*/
  	function displayForm(){  	
  		global $option;
  		    
  		$cid		= JRequest::getVar( 'cid', array(0), '', 'array' );
		$edit		= JRequest::getVar('edit',true);
		$me 		= JFactory::getUser();
		JArrayHelper::toInteger($cid, array(0));

		$db 		=& JFactory::getDBO();
		if($edit)
			$user 		=& JUser::getInstance( $cid[0] );
		else
			$user 		=& JUser::getInstance();

		$myuser		=& JFactory::getUser();
		$acl		=& JFactory::getACL();

		// Check for post data in the event that we are returning
		// from a unsuccessful attempt to save data
		$post = JRequest::get('post');
		if ( $post ) {
			$user->bind($post);
		}		
		$this->assignRef('me', 		$me);
		$this->assignRef('lists',	$lists);
		$this->assignRef('user',	$user);
		$this->assignRef('contact',	$contact);
		$this->assignRef('option',	$option);
	}	

	/**
	 * Get view list
	 *
	 * @return list views
	 */
	function &_getViewLists($fieldList)
	{
		global $mainframe, $option;

		$db = &JFactory::getDBO();
               
		$lists['order'] = JRequest::getVar('filter_order', 'a.id');
		$lists['order_Dir']	= $mainframe->getUserStateFromRequest( $option.".jaemployers.filter_order_Dir",	'filter_order_Dir',	"DESC",	'word' );				
    	
		$search	= $mainframe->getUserStateFromRequest( JBCOMNAME .".jaemployers.search",			'user_search',			'',				'string' );
		$lists['search'] = trim(JString::strtolower ( $search ));
        			
       	/* By category */
       $item = new stdClass();
		
		foreach ($fieldList as $field){
			if($field->is_on_filter && ($field->field_type=='SELECT'||$field->field_type=='MSELECT')){
				$item->{$field->field_name} = $mainframe->getUserStateFromRequest( $option.".jaemployers.".$field->field_name,   $field->field_name,   ' ', 'string' );				
				$lists['filter'][$field->field_name] = rendfield($item, $field, true,false,true);
			}
		}	
       
		$lists['is_featured']	= $mainframe->getUserStateFromRequest( $option.".jaemployers.is_featured",	'is_featured',		'',	'cmd' );
		if($lists['is_featured']=='') $lists['is_featured'] = -1;
		
		$lists['approved']	= $mainframe->getUserStateFromRequest( $option.".jaemployers.approved",	'approved',		'',	'cmd' );
		if($lists['approved']=='') $lists['approved'] = -1;
		
        // filter_state
        $lists['option']    = $option;

		return $lists;
	}
		   
    function menu()
	{
		$task = JRequest::getVar('task', 'user');
		$cid = JRequest::getVar('cid');
		if (is_array($cid))
		{
			JArrayHelper::toInteger($cid);
        	$cid = $cid[0];
		}
		 
        
		?>
			<div class="t">
				<div class="t">
					<div class="t"></div>
				</div>
			</div>
			<div class="m">
				<ul id="submenu">
					<li>
						<a href="index.php?option=com_jajobboard&view=jaemployers&task=user&cid[]=<?php echo $cid;?>"class="<?php if($task==null||$task=='user')echo 'active' ?>">
							<?php echo JText::_( 'Membership details' ); ?>
						</a>
					</li>				
					<li>
						<a href="index.php?option=com_jajobboard&view=jaemployers&task=account&cid[]=<?php echo $cid;?>" class="<?php if($task=='account')echo 'active' ?>">
							<?php echo JText::_( 'Account details' ); ?>
						</a>
					</li>
					<li>			
							<a href="index.php?option=com_jajobboard&view=jaemployers&task=profile&cid[]=<?php echo $cid;?>" class="<?php if($task=='profile')echo 'active' ?>" >
								<?php echo JText::_( 'Profile Details' ); ?>
							</a>
					</li>	
					<li>
						<a href="index.php?option=com_jajobboard&view=jatransactions&task=trans_viewbyuser&userid=<?php echo $cid;?>" class="<?php if($task=='viewbyuser')echo 'active' ?>">
							<?php echo JText::_( 'Transactions' ); ?>
						</a>
					</li>

				</ul>
				<div class="clr"></div>
			</div>
			<div class="b">
				<div class="b">
					<div class="b"></div>
				</div>
			</div>		
		<?php		
	}	
}
?>